package com.xyp.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xyp.sso.testexecution.CommonExecutor;
import com.xyp.sso.testexecution.CommonExecutor.CommonRunnable;
import com.xyp.sso.testinterfaces.SSODubboInterface;

@Controller
public class LoginController {

    @Reference(interfaceClass = SSODubboInterface.class)
    private SSODubboInterface dubboInterface;

    @RequestMapping(value = "/login")
    @ResponseBody
    public String loginUser(HttpServletRequest request, HttpServletResponse response) {

        Map<String, String[]> map = request.getParameterMap();

        for (String key : map.keySet()) {
            System.out.println(key + "   " + map.get(key));
        }

        return "/index";

    }

    @RequestMapping(value = "toDubbo")
    public String toDubbo(HttpServletRequest request, HttpServletResponse response) {

        return CommonExecutor.execution(new CommonRunnable() {

            @Override
            public String exec() {
                return dubboInterface.testDubboShiro();
            }
        });

    }

}
